<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-container>
        <el-header style="background-color: #0095d7">
            <h1 style="color: white;font-size: 22px">
                吃点啥商城后台管理系统
                <span v-if="user.nickname!=null" style="float: right;font-size: 15px">欢迎{{user.nickname}}回来
                    <a href="javascript:void(0) " @click="logout()">退出登录</a>
                </span>
            </h1>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu style="height: 700px"
                         @select="handleSelect"
                         default-active="2"
                         class="el-menu-vertical-demo">
<!--                    分类管理-->
                    <el-submenu index="1">
                        <template slot="title">
                            <i class="el-icon-s-flag"></i>
                            <span>分类管理</span>
                        </template>
                        <el-menu-item index="1-1" >分类列表</el-menu-item>
                        <el-menu-item index="1-2">添加分类</el-menu-item>
                    </el-submenu>


<!--                    轮播图-->
                    <el-submenu index="2">
                        <template slot="title">
                            <i class="el-icon-picture"></i>
                            <span>轮播图管理</span>
                        </template>
                        <el-menu-item index="2-1">轮播图列表</el-menu-item>
                        <el-menu-item index="2-2">添加轮播图</el-menu-item>
                    </el-submenu>
                    <el-submenu index="3">
                        <template slot="title">
                            <i class="el-icon-shopping-cart-2"></i>
                            <span>商品管理</span>
                        </template>
                        <el-menu-item index="3-1">商品列表</el-menu-item>
                        <el-menu-item index="3-2">添加商品</el-menu-item>
                    </el-submenu>
                    <el-submenu index="4">
                        <template slot="title">
                            <i class="el-icon-shopping-cart-2"></i>
                            <span>用户管理</span>
                        </template>
                        <el-menu-item index="4-1">用户列表</el-menu-item>
                    </el-submenu>
                    <el-submenu index="5">
                        <template slot="title">
                            <i class="el-icon-shopping-cart-2"></i>
                            <span>订单管理</span>
                        </template>
                        <el-menu-item index="5-1">堂食订单列表</el-menu-item>
                        <el-menu-item index="5-2">配送订单列表</el-menu-item>
                    </el-submenu>
                    <el-submenu index="6">
                        <template slot="title">
                            <i class="el-icon-shopping-cart-2"></i>
                            <span>交易统计</span>
                        </template>
                        <el-menu-item index="6-1">订单统计</el-menu-item>
                        <el-menu-item index="6-2">交易统计</el-menu-item>
                        <el-menu-item index="6-3">交易走势图</el-menu-item>
                    </el-submenu>
                </el-menu>

            </el-aside>
            <el-main>
                <el-table v-if="currentIndex=='1-1'"
                          :data="categoryArr"
                          style="width: 100%">
                    <!--type=index 设置这一列显示的内容为编号-->
                    <el-table-column type="index" label="编号"></el-table-column>
                    <el-table-column
                            prop="title"
                            label="分类名称"
                            width="180">
                    </el-table-column>
                    <el-table-column label="操作">
                        <!--scope里面装着当前行所对应的对象信息
                        scope.$index 得到当前行对应的对象在数组中的下标
                        scope.row 得到当前行对应的对象
                        -->
                        <template slot-scope="scope">
                            <el-button size="mini" @click="categoryUpdate(scope.row)"
                                       type="success">修改
                            </el-button>
                            <el-popconfirm
                                    title="确定删除此分类吗?"
                                    @confirm="categoryDelete(scope.$index, scope.row)"
                            >
                                <el-button slot="reference" size="mini"
                                           type="danger">删除
                                </el-button>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>
                <el-table v-if="currentIndex=='2-1'"
                          :data="bannerArr"
                          style="width: 100%">
                    <!--type=index 设置这一列显示的内容为编号-->
                    <el-table-column type="index" label="编号"></el-table-column>
                    <el-table-column
                            label="轮播图"
                            width="180">
                        <template slot-scope="scope">
                            <!--scope.row代表当前行对应数组中的对象-->
                            <img :src="scope.row.url" width="100%">
                        </template>
                    </el-table-column>
                    <el-table-column label="操作">
                        <!--scope里面装着当前行所对应的对象信息
                        scope.$index 得到当前行对应的对象在数组中的下标
                        scope.row 得到当前行对应的对象
                        -->
                        <template slot-scope="scope">
                            <el-button size="mini" @click="bannerUpdate(scope.row)"
                                       type="success">修改
                            </el-button>
                            <el-popconfirm
                                    title="确定删除此分类吗?"
                                    @confirm="bannerDelete(scope.$index, scope.row)"
                            >
                                <el-button slot="reference" size="mini"
                                           type="danger">删除
                                </el-button>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>
                <el-table v-if="currentIndex=='3-1'"
                          :data="productArr"
                          style="width: 100%">
                    <!--type=index 设置这一列显示的内容为编号-->
                    <el-table-column type="index" label="编号"></el-table-column>
                    <el-table-column prop="foodName" label="商品标题" width="100"></el-table-column>
                    <el-table-column prop="price" label="价格" width="80"></el-table-column>
                    <el-table-column prop="oldPrice" label="原价" width="80"></el-table-column>
                    <el-table-column prop="saleCount" label="销量" width="80"></el-table-column>
                    <el-table-column prop="state" label="状态" width="80">

                    </el-table-column>
                    <el-table-column
                            label="商品图片"
                            width="100">
                        <template slot-scope="scope">
                            <!--scope.row代表当前行对应数组中的对象-->
                            <img :src="scope.row.url" width="100%">
                        </template>
                    </el-table-column>
                    <el-table-column label="操作">
                        <!--scope里面装着当前行所对应的对象信息
                        scope.$index 得到当前行对应的对象在数组中的下标
                        scope.row 得到当前行对应的对象
                        -->
                        <template slot-scope="scope">
                            <el-button size="mini" @click="productUpdate(scope.row)"
                                       type="success">修改
                            </el-button>
                            <el-popconfirm
                                    title="确定删除此商品吗?"
                                    @confirm="productDelete(scope.$index, scope.row)"
                            >
                                <el-button slot="reference" size="mini"
                                           type="danger">删除
                                </el-button>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>
                <el-table v-if="currentIndex=='5-1'"
                                      :data="ordersArr"
                                      style="width: 100%">
                <!--type=index 设置这一列显示的内容为编号-->
                <el-table-column type="index" label="编号"></el-table-column>
                <el-table-column prop="title" label="订单编号" width="200"></el-table-column>
                <el-table-column prop="sumPrice" label="总价格" width="80"></el-table-column>
                <el-table-column prop="tableId" label="桌号" width="80"></el-table-column>
                <el-table-column prop="created" label="下单时间" width="80"></el-table-column>
               <!-- <el-table-column
                        label="商品图片"
                        width="100">
                    <template slot-scope="scope">
                        &lt;!&ndash;scope.row代表当前行对应数组中的对象&ndash;&gt;
                        <img :src="scope.row.url" width="100%">
                    </template>
                </el-table-column>-->
                <el-table-column label="操作">
                    <!--scope里面装着当前行所对应的对象信息
                    scope.$index 得到当前行对应的对象在数组中的下标
                    scope.row 得到当前行对应的对象
                    -->
                    <template slot-scope="scope">
                      <el-popover  placement="right"
                                   width="400"
                                   trigger="click">

                              <el-form  label-width="80px"  ><!--:model="order"-->
                                  <el-form-item label="桌号">
                                      <el-input type="text"></el-input>
                                  </el-form-item>
                                  <el-form-item label="桌号">
                                      <el-select v-model="categoryArr">
                                          <el-option v-for="c in categoryArr" :label="c.name" :value="c.id"></el-option>
                                      </el-select>
                                  </el-form-item>
                                  <el-form-item label="桌号">
                                      <el-input  type="text" v-model="o.id"></el-input>
                                  </el-form-item>
                                  <el-form-item label="桌号">
                                      <el-input v-model="o.tableId"type="text"></el-input>
                                  </el-form-item>
                                  <el-form-item label="桌号">
                                      <el-input v-model="o.sumPrice"type="text"></el-input>
                                  </el-form-item>  <el-form-item label="桌号">
                                      <el-input v-model="o.dertails"type="text"></el-input>
                                  </el-form-item>  <el-form-item label="桌号">
                                      <el-input v-model="o.url"type="text"></el-input>
                                  </el-form-item>
                              </el-form>

                          <el-button slot="reference" @click="selectByOrdersId(scope.row)">查看详情</el-button>
                      </el-popover>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </el-table>
            </el-main>
        </el-container>
    </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                currentIndex: "1-1",
                categoryArr: [],
                bannerArr: [],
                productArr: [],
                user: {},
                ordersArr:[],
                o:{
                    id:"1111",
                    created:"222",
                    userId:"333",
                    tableId:"444",
                    sumPrice:"555",
                    dertails:"666",
                    url:"777",
                    food:[]
                }
            }
        },
        methods: {
            //查询订单详情
            selectByOrdersId(orders){
                axios.get("/order/selectOrderById?id="+orders.id).then(function (response) {
                    console.log(response.data);
                    this.o = response.data;
                })
            },


            logout() {
                if (confirm("确定退出?")) {
                    axios.get("/logout").then(function () {
                        location.href = "/"
                    })
                }

            },
            categoryDelete(index, category) {
                axios.get("/category/delete?id=" + category.id).then(function (response) {
                    v.categoryArr.splice(index, 1);
                })
            },
            bannerDelete(index, banner) {
                axios.get("/banner/delete?id=" + banner.id).then(function (response) {
                    v.bannerArr.splice(index, 1);
                })
            },
            productDelete(index, product) {
                axios.get("/product/delete?id=" + product.id).then(function (response) {
                    v.productArr.splice(index, 1)
                })
            },
            productUpdate(product) {
                location.href = "/updateProduct.html?id=" + product.id;
            },
            bannerUpdate(banner) {
                location.href = "/UpdateBanner.html?url=" + banner.url + "&id=" + banner.id;
            },
            categoryUpdate(category) {
                let title = prompt("请输入新的分类的名称")
                if (title == null) {
                    return;
                }
                if (title == "") {
                    v.$message("分类名称不能为空");
                    return;
                }
                let c = {id: category.id, title: title}
                axios.post("/category/update", c).then(function () {
                    category.title = title;
                })
            },
            handleSelect(key, keyPath) {
                if (key == '1-2') {
                    let title = prompt("请输入分类的名称")
                    if (title == null) {
                        return;
                    }
                    if (title == "") {
                        v.$message("分类名称不能为空");
                        return;
                    }
                    axios.get("/category/insert?title=" + title).then(function (response) {
                        alert(response.data)
                        v.categoryArr = response.data;
                    })
                } else if (key == '2-2') {
                    location.href = "/insertBanner.html"
                } else if (key == '3-2') {
                    location.href = "/insertProduct.html";
                } else {
                    v.currentIndex = key;
                }
            }
        },
        created:function () {
            axios.get("/category/select").then(function (response) {
                v.categoryArr=response.data;
            })
            axios.get("/banner/select").then(function (response) {
                v.bannerArr = response.data;
            })
            axios.get("/product/select").then(function (response) {
                v.productArr=response.data;
            })
            axios.post("/order/select").then(function (response) {
                v.ordersArr= response.data;
            })

        }
    })
</script>
</html>